package com.tianhao.luo.graph;

import java.util.HashMap;
import java.util.List;

/**
 * 圆的计算工厂
 * @author tianhao.luo
 * @date 2019/12/19 10:13
 */
public class CircleCalculateFactory implements CalculateFactory{
    /**
     * 计算面积
     *
     * @param graph 图形
     * @return 面积
     */
    @Override
    public float calculateArea(Graph graph) {
        Circle circle = (Circle) graph;
        HashMap<Integer, List<Line>> map = circle.getMap();
        List<Line> lines = map.get(1);
        Line line = lines.get(0);
        int length = line.getLength();
        float r = 1F * (length/(2*circle.getPI()));
        return r*r*circle.getPI();
    }

    /**
     * 计算周长
     *
     * @param graph 图形
     * @return 周长
     */
    @Override
    public float calculatePerimeter(Graph graph) {
        Circle circle = (Circle) graph;
        HashMap<Integer, List<Line>> map = circle.getMap();
        List<Line> lines = map.get(1);
        Line line = lines.get(0);
        return line.getLength();
    }
}
